package com.education.springbootdemo.domain;

import lombok.Data;

import java.io.Serializable;


@Data
public class Resp<T> implements Serializable {
    private int code;
    private T data;
    private String msg;

    private Resp(T data) {
        this.code = 200;
        this.data = data;
    }

    public static <T> Resp<T> success(T data) {
          Resp resp = new Resp<>(data);
            resp.setCode(200);
            resp.setMsg("success");
            resp.setData(data);
            return resp;
    }

    public static <T> Resp<T> error(int code, String msg) {
        Resp resp = new Resp<>(null);
        resp.setCode(code);
        resp.setMsg(msg);
        return resp;
    }
}
